<extend name="Public/base" />
<!--<link rel="stylesheet" type="text/css" href="__PUBLIC__/selectjs/demo.css"/>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/selectjs/themes/easydropdown.css"/>-->
<block name="main">
    <fieldset class="layui-elem-field">
        <legend>订单管理 - {:(isset($detail['id'])?'编辑':'新增')}订单</legend>
        <div class="layui-field-box">
            <form class="layui-form" action="">
                <if condition="isset($detail['id'])">
                    <input type="hidden" name="id" value="{$detail['id']}">
                </if>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 代理</label>
                    <div class="layui-inline">
                        <select name="expressName" lay-verify="required">
                            <option value="0">快递公司</option>
                            <volist name="express" id="vo">
                                <option value="{$key}" {:($detail['expressName'] == $key?'selected':'')}>{$vo}</option>
                            </volist>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 快递单号</label>
                    <div class="layui-input-block">
                        <input type="text" name="expressNumber" required value="{:(isset($detail['expressNumber'])?$detail['expressNumber']:'')}" lay-verify="required" placeholder="快递单号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"> 通知消息</label>
                    <span>亲爱的,咱们订购的猕猴桃已经发货 （中通快递{$detail['expressNumber']}）  咱们随时关注物流信息哈</span>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"> 快递路由</label>
                    <div class="layui-input-block">
                        <textarea class="layui-textarea" name="jobConfig" placeholder="路由信息">{:(isset($detail['expressLog'])?$detail['expressLog']:'')}</textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="admin-form">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </fieldset>
</block>
<block name="myScript">
    <script>
        layui.use('form', function(){
            var form = layui.form();
            form.on('submit(admin-form)', function(data){
                $.ajax({
                    type: "POST",
                    url: '{:U("put")}',
                    data: data.field,
                    success: function(msg){
                        if( msg.code == 1 ){
                            parent.location.reload();
                        }else{
                            parent.layer.msg(msg.msg, {
                                icon: 5,
                                shade: [0.6, '#393D49'],
                                time:1500
                            });
                        }
                    }
                });
                return false;
            });

        });
    </script>
    <script>
        layui.use('form', function(){
            //如果有需要到镇的改改就可以实现
            var form = layui.form(),
                    layer = layui.layer,
                    $ = layui.jquery;
            var url =  '{:U("getArea")}'; //数据请求地址
            var province = "广东省"; //编辑需要的省
            var city = "广州市"; //编辑需要的市
            var district = "天河区"; //编辑需要的县/区
            getJSON(url,$("select[name='province']").closest("div"));
            form.on('select(state)', function(data){
                $that = $(data.elem);
                urls = url+"&id="+data.value;
                getJSON(urls,$that.closest("div").next());
            });
            function getJSON(urls,even){
                $.getJSON(urls, function(json){
                    var pid = 0;
                    var name = even.find("select").attr("name");
                    var select = "<select name=\"" + name + "\" lay-filter=\"state\">";
                    select += "<option value=\"0\">请选择 </option>";
                    $(json).each(function(){
                        select += "<option value=\"" + this.id + "\"";
                        if(province == this.value || city == this.value || district == this.value){
                            select += " selected=\"selected\" ";
                            pid = this.id;
                        }
                        select += ">" + this.value + "</option>";
                    });
                    select += "</select>";
                    even.html(select);
                    var nextName = even.next().find("select").attr("name");
                    even.next().html("<select name=\"" + nextName + "\" lay-filter=\"state\"><option value=\"0\">请选择 </option></select>");
                    form.render('select');
                    if(pid != 0){
                        getJSON(url+"?id="+pid,even.next());
                    }
                });
            }
        });
    </script>
</block>